<template>
  <el-dialog title="批量设置" :visible.sync="dialogVisible" width="20%" center>
    <el-radio-group v-model="radio" class="group">
      <el-radio :label="1">上架</el-radio>
      <el-radio :label="0">下架</el-radio>
    </el-radio-group>
    <span slot="footer" class="dialog-footer">
      <el-button @click="dialogVisible = false">取消</el-button>
      <el-button type="primary" @click="confirm" :disabled="radio == null"
        >确定</el-button
      >
    </span>
  </el-dialog>
</template>
<script>
import { batchStatus } from "@/views/wxaMallModule/api/productPublic";
import { mapState } from "vuex";
export default {
  data() {
    return {
      dialogVisible: false,
      radio: null,
      goodsIds: [],
    };
  },
  components: {},
  mounted() {},
  computed: {
    ...mapState({
      mainShopStatus: (state) => state.user.mainShopStatus,
    }),
  },
  methods: {
    open(row) {
      if (row && row.length > 0) {
        row.forEach((e) => {
          this.goodsIds.push(e.id);
        });
        this.dialogVisible = true;
      }
      return new Promise((resolve, reject) => {
        this.resolve = resolve;
        this.reject = reject;
      });
    },
    confirm() {
      let { mainShopStatus, goodsIds, radio } = this;
      batchStatus({
        goodsIds,
        status: radio,
        mainShopStatus,
      }).then((res) => {
        this.$message({
          type: "success",
          message: "更新状态成功",
        });
        this.close();
      });
    },
    close() {
      this.goodsIds = [];
      this.radio = null;
      this.dialogVisible = false;
      this.resolve && this.resolve();
    },
  },
};
</script>
<style lang='scss' scoped>
.group {
  width: 100%;
  display: flex;
  justify-content: space-around;
}
</style>